All Packages Class Hierarchy This Package Previous Next Index
Class sun.server.util.LRUCache
java.lang.Object
|
+----java.util.Dictionary
|
+----java.util.Hashtable
|
+----sun.server.util.LRUCache
- public class LRUCache
- extends Hashtable
The LRUCache is a bounded hashtable where the least recently used entries
are purged from the hashtable to make room for new ones. The objects stored
are all mandated to implement the cacheable interface. This LRUCache is
bounded by a configurable size. Whenever a new Cacheable object is inserted,
its made sure that the size of the cache remains below the configured
maximum. If the maximum would be exceeded by adding this new element, old
least recently used elements are thrown out until the enough room is made for
the new element. If enough room cannot be made for the new element, an
OutOfMemory exception is thrown.
- See Also:
- Cacheable
-
LRUCache(int)
- Constructs a new, empty LRUCache.
-
LRUCache(int, float, int)
- Constructs a new, empty LRUCache with the specified initial
capacity, the specified load factor and the specified max number
of entries.
-
LRUCache(int, int)
- Constructs a new, empty LRUCache with the specified initial
capacity.
-
get(Object)
- Gets the object associated with the specified key in the
hashtable.
-
getAvailableSize()
- The total amount of free space available
in the cache for storing new elements
-
getTotalSize()
- The total size this cache was configured with
at construction time.
-
put(Object, Cacheable)
- Puts the specified element into the hashtable, using the specified
key.
-
put(Object, Object)
- Only Cacheable entries can be stored in this cache.
-
remove(Object)
- Removes the element corresponding to the key.
LRUCache
public LRUCache(int initialCapacity,
float loadFactor,
int maxSize)
- Constructs a new, empty LRUCache with the specified initial
capacity, the specified load factor and the specified max number
of entries.
- Parameters:
- initialCapacity - the initial number of buckets
- loadFactor - a number between 0.0 and 1.0, it defines
the threshold for rehashing the LRUCache into
a bigger one.
- maxSize - - the maximum size this cache can grow to. Once this
size limit is reached, entries will be thrown away
in LRU to make space for new entries in the cache.
- Throws: IllegalArgumentException
- If the initial capacity
is less than or equal to zero.
- Throws: IllegalArgumentException
- If the load factor is
less than or equal to zero.
LRUCache
public LRUCache(int initialCapacity,
int maxSize)
- Constructs a new, empty LRUCache with the specified initial
capacity.
- Parameters:
- initialCapacity - the initial number of buckets
- maxSize - - the maximum size this cache can grow to. Once this
size limit is reached, entries will be thrown away
in LRU to make space for new entries in the cache.
LRUCache
public LRUCache(int maxSize)
- Constructs a new, empty LRUCache. A default capacity and load factor
is used. Note that the LRUCache will automatically grow when it gets
full.
- Parameters:
- maxSize - - the maximum size this cache can grow to. Once this
size limit is reached, entries will be thrown away
in LRU to make space for new entries in the cache.
put
public synchronized Object put(Object key,
Cacheable c)
- Puts the specified element into the hashtable, using the specified
key. The element may be retrieved by doing a get() with the same key.
The key and the element cannot be null.
- Parameters:
- key - the specified key in the hashtable
- value - the specified element that implements the Cacheable interface
- Returns:
- the old value of the key, or null if it did not have one.
- Throws: NullPointerException
- If the value of the element
is equal to null.
- Throws: OutOfMemoryError
- If the cache cannot accomodate the size of
the object.
- See Also:
- get
put
public synchronized Object put(Object key,
Object value)
- Only Cacheable entries can be stored in this cache. An attempt to
insert anything else results in an IllegalArgumentException
- Parameters:
- key - the specified key in the hashtable
- value - the specified element that implements the Cacheable interface
- Returns:
- the old value of the key, or null if it did not have one.
- Throws: IllegalArgumentException
- if Object does not implement Cacheable
- Overrides:
- put in class Hashtable
- See Also:
- get
get
public synchronized Object get(Object key)
- Gets the object associated with the specified key in the
hashtable.
- Parameters:
- key - the specified key
- Returns:
- s the element for the key or null if the key
is not defined in the hash table.
- Overrides:
- get in class Hashtable
- See Also:
- put
remove
public synchronized Object remove(Object key)
- Removes the element corresponding to the key. Does nothing if the
key is not present.
- Parameters:
- key - the key that needs to be removed
- Returns:
- the value of key, or null if the key was not found.
- Overrides:
- remove in class Hashtable
getAvailableSize
public int getAvailableSize()
- The total amount of free space available
in the cache for storing new elements
getTotalSize
public int getTotalSize()
- The total size this cache was configured with
at construction time.
All Packages Class Hierarchy This Package Previous Next Index